package com.ssyt.yt1.day14.innerclass.d;

/**
 * 在方法内部类/匿名内部类访问局部变量为什么一定要加final ?
 * 
 * @author Administrator
 *
 */
public class InnerClassWithFinalDemo {

	public static void main(String[] args) {
		Fruit fruit = test();
		System.out.println(fruit.getName());
	}

	public static Fruit test() {
		// final在jdk8以后是隐式存在的！
		String name = "未知名水果";

		Fruit fruit = new Fruit() {

			@Override
			public String getName() {
				return name;
			}
		};

		// name = "a";

		return fruit;
	}
}
